<template>
  <div @click.stop="$parent.$parent.onEditer(index)" class="drag optional" :class="{selected: index === selectedIndex}">
    <div class="diy-newcoupon" :style="{background:item.style.background,padding: item.style.paddingTop+'px '+item.style.paddingLR+'px '+item.style.paddingBom+'px '+item.style.paddingLR+'px'}">
      <div class="quan">
        <div v-for="(coupon, index) in item.data" :key="index" class="coupon_list" v-if="item.params.source!='auto'||(item.params.source=='auto'&&item.params.auto.showNum>index)">
          <div class="coupon_container">
            <div class="coupon_money">
                <div class="money">{{ dealWithPrice(coupon.reduce_price) }} 元</div>
                <div class="coupon-type-text">{{ dealWithText(coupon.min_price) }}</div>
            </div>
            <div class="coupon_btm">
                <div class="coupon_range" v-if="coupon.range.length > 0">
                    <div v-for="(range_items, index) in coupon.range" :key="index" class="range_item">
                        {{ index + 1 + '、' + range_items }}
                    </div>
                </div>
                <button class="coupon_btn">立即领取</button>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="btn-edit-del">
      <div class="btn-del" @click.stop="$parent.$parent.onDeleleItem(index)">删除</div>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {

      };
    },
    props: ['item', 'index', 'selectedIndex'],
    methods: {
      dealWithText(min_price) {
          if (min_price !== '0.00') {
              const arr = min_price.split('.');
              const text = arr[1] === '00' ? arr[0] : min_price;
              return `满${text}可用`;
          } else {
              return '无门槛';
          }
      },
      dealWithPrice(price) {
        if(price.indexOf(".") != -1){
          const arr = price.split('.');
          const curPriceText = arr[1] === '00' ? arr[0] : price;
          return curPriceText;
        }else{
          return price;
        }
      },
    }
  };
</script>

<style>
  .diy-newcoupon {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    overflow-x: auto;
  }

  .diy-newcoupon .coupon-wrapper {

  }

  .diy-newcoupon .coupon-wrapper .coupon-item {
    border-radius: 4px;
    overflow: hidden;
    margin-right: 10px;
  }

  .diy-newcoupon .coupon-wrapper .left-content {
    width: 80px;
    height: 56px;
    padding: 0;
    box-sizing: border-box;
    color: #FFFFFF;
    flex: 1;
    background: #FF4C01;
  }

  .diy-newcoupon .coupon-wrapper .left-content .price {
    font-size: 20px;
    font-weight: bold;
  }

  .diy-newcoupon .coupon-wrapper .content-top {
    font-size: 12px;
    text-align: center;
  }
  .diy-newcoupon .coupon-wrapper .content-bottom{
    font-size: 10px;
    text-align: center;
  }
  .diy-newcoupon .coupon-wrapper .right-receive {
    height: 56px;
    width: 26px;
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    border-left: 1px dashed #ffffff;
    text-align: center;
    color: #FFF5D4;
    background: #FF4C01;
    font-size: 9px;
    line-height: 10px;

  }
  .lr-tb{
    width: 13px;
  }

  .diy-newcoupon .quan {
      width: 100%;
      border-radius: 8px;
      background: #fef2e2;
      padding: 9px;
      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
  }

  .diy-newcoupon .quan .coupon_list {
      padding: 4px 4px;
      flex-basis: 33%;
  }

  .diy-newcoupon .quan .coupon_container {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-between;
      background-color: #fff;
  }
  .diy-newcoupon .quan .coupon_list .coupon_money {
      width: 100%;
      height: 65px;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      background-image: url('https://ossimg.jiumaioda.com/wechat/static/newPeopleCouponBg.png');
      background-size: 100% 100%;
      color: #fff;
  }
  .diy-newcoupon .quan .coupon_money .money {
      font-size: 16px;
      font-weight: normal;
      line-height: 20px;
      text-align: center;
      color: #fff;
      display: flex;
      justify-content: center;
  }
  .diy-newcoupon .quan .coupon_money .money {
      font-size: 19px;
      font-family: Verdana, Geneva, Tahoma, sans-serif;
      font-weight: bold;
  }
  .diy-newcoupon .quan .coupon_btm {
      flex: 1;
      min-height: 50px;
      width: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding-bottom: 10px;
      padding-top:10px;
  }
  .diy-newcoupon .quan .coupon_btm .coupon_range {
      font-size: 10px;
      line-height: 20px;
  }
  .diy-newcoupon .quan .coupon_btm .coupon_btn {
      margin-top: 5px;
      background: #BB0024;
      width: 66px;
      height: 22px;
      color: #fff;
      border: 1px solid #BB0024;
      font-size: 11px;
      overflow: visible;
      border-radius: 11px;
  }
  .diy-newcoupon .quan .coupon_img {
      width: 100%;
      height: 65px;
  }
</style>
